package com.dsj.gxrd.modules.activity.service.impl;

import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dsj.gxrd.modules.activity.domain.dto.RdGroupDto;
import com.dsj.gxrd.modules.activity.domain.entity.RdGroup;
import com.dsj.gxrd.modules.activity.domain.vo.GroupUserVo;
import com.dsj.gxrd.modules.activity.domain.vo.RdGroupVo;
import com.dsj.gxrd.modules.activity.mapper.RdGroupMapper;
import com.dsj.gxrd.modules.activity.mapper.RdGroupUserMapper;
import com.dsj.gxrd.modules.activity.service.RdGroupService;
import com.dsj.gxrd.modules.activity.service.RdGroupUserService;
import com.dsj.gxrd.utils.BaseEntityHandlerUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author songpin566
 * @date 2023/10/09
 **/
@Service
public class RdGroupServiceImpl extends ServiceImpl<RdGroupMapper, RdGroup> implements RdGroupService {

    @Autowired
    private RdGroupMapper rdGroupMapper;

    @Override
    public List<RdGroupVo> selectRdGroupList(String name, String groupName) {
        List<RdGroup> groupList = rdGroupMapper.selectRdGroupList(name, groupName);
        List<RdGroupVo> list = new ArrayList<>();
        for (RdGroup rdGroup : groupList) {
            RdGroupVo rdGroupVo = BeanUtils.copyProperties(rdGroup, RdGroupVo.class);
            String ids = rdGroup.getIds();
            if(StringUtils.isNotEmpty(ids)){
                List<Long> collect = Arrays.stream(ids.split(",")).mapToLong(Long::parseLong).boxed().collect(Collectors.toList());
                rdGroupVo.setGroupUserIds(collect);
            }
            list.add(rdGroupVo);
        }
        return list;
    }

    @Override
    public List<GroupUserVo> getInfo(Long groupId, String name) {
        return rdGroupMapper.getInfo(groupId,name);
    }



}
